package VIEW;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class EscolhaView extends javax.swing.JFrame {

    /**
     * Creates new form EscolhaView
     */
    public EscolhaView() {
            
        initComponents();
          
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        compraRadioButton = new javax.swing.JRadioButton();
        blogRadioButton = new javax.swing.JRadioButton();
        relatorioRadioButton = new javax.swing.JRadioButton();
        cpfLabel = new javax.swing.JLabel();
        cpfTextField = new java.awt.TextField();
        avancarButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Rock in Rio");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        compraRadioButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        compraRadioButton.setText("Compra");
        compraRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                compraRadioButtonActionPerformed(evt);
            }
        });

        blogRadioButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        blogRadioButton.setText("Blogs");
        blogRadioButton.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        blogRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                blogRadioButtonActionPerformed(evt);
            }
        });

        relatorioRadioButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        relatorioRadioButton.setText("Relatórios");
        relatorioRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                relatorioRadioButtonActionPerformed(evt);
            }
        });

        cpfLabel.setVisible(false);
        cpfLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        cpfLabel.setText("CPF");

        cpfTextField.setVisible(false);
        cpfTextField.addTextListener(new java.awt.event.TextListener() {
            public void textValueChanged(java.awt.event.TextEvent evt) {
                cpfTextFieldTextValueChanged(evt);
            }
        });
        cpfTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cpfTextFieldActionPerformed(evt);
            }
        });

        avancarButton.setVisible(false);
        avancarButton.setText("Avançar");
        avancarButton.setActionCommand("Prosseguir");
        avancarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                avancarButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(compraRadioButton)
                        .addGap(4, 4, 4)
                        .addComponent(blogRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(relatorioRadioButton)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cpfLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cpfTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(avancarButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(compraRadioButton)
                    .addComponent(blogRadioButton)
                    .addComponent(relatorioRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cpfLabel)
                    .addComponent(cpfTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(avancarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 36, Short.MAX_VALUE))
        );

        avancarButton.getAccessibleContext().setAccessibleName("");

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/VIEW/logo-rock-in-rio.JPG"))); // NOI18N
        jLabel1.setText("logo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
       
    }//GEN-LAST:event_formWindowActivated

    private void avancarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_avancarButtonActionPerformed

        Integer cpf = 0;

        if(cpfTextField.isVisible() == true){
            try{
                cpf = Integer.parseInt(cpfTextField.getText());
            } catch (NumberFormatException e){
                cpfTextField.setText("");
                JOptionPane.showMessageDialog(null, "CPF composto apenas por números!");
                return;
            }
        }

        if (compraRadioButton.isSelected()) {
            LineUpView LineUp = null;
            try {
                LineUp = new LineUpView();
            } catch (SQLException ex) {
                Logger.getLogger(EscolhaView.class.getName()).log(Level.SEVERE, null, ex);
            }
            LineUp.setLocationRelativeTo(null);
            LineUp.setVisible(true);            
            this.dispose();
        } else if (blogRadioButton.isSelected()) {
            JOptionPane.showMessageDialog(null, "Funcionalidade não desenvolvida! =(");
        } else if (relatorioRadioButton.isSelected()) {
            RelatoriosView relatorioView = null;
            relatorioView = new RelatoriosView();
            relatorioView.setLocationRelativeTo(null);
            relatorioView.setVisible(true);            
            this.dispose();
        } else {
            JOptionPane.showMessageDialog(null, "Escolha uma opção para prosseguir.");
        } 
    }//GEN-LAST:event_avancarButtonActionPerformed

    private void cpfTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cpfTextFieldActionPerformed

    }//GEN-LAST:event_cpfTextFieldActionPerformed

    private void cpfTextFieldTextValueChanged(java.awt.event.TextEvent evt) {//GEN-FIRST:event_cpfTextFieldTextValueChanged
        if(cpfTextField.toString().length() > 0)
        avancarButton.setEnabled(true);

        else{
            avancarButton.setEnabled(false);
        }
    }//GEN-LAST:event_cpfTextFieldTextValueChanged

    private void relatorioRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relatorioRadioButtonActionPerformed
        compraRadioButton.setSelected(false);
        blogRadioButton.setSelected(false);
        avancarButton.setEnabled(false);

        if(relatorioRadioButton.isSelected() == false){
            cpfLabel.setVisible(false);
            cpfTextField.setVisible(false);
            avancarButton.setVisible(false);
        }
        else {
            cpfLabel.setVisible(true);
            cpfTextField.setVisible(true);
            avancarButton.setVisible(true);

        }
    }//GEN-LAST:event_relatorioRadioButtonActionPerformed

    private void blogRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blogRadioButtonActionPerformed
        compraRadioButton.setSelected(false);
        relatorioRadioButton.setSelected(false);
        avancarButton.setEnabled(false);

        if(blogRadioButton.isSelected() == false){
            cpfLabel.setVisible(false);
            cpfTextField.setVisible(false);
            avancarButton.setVisible(false);
        }
        else {
            cpfLabel.setVisible(true);
            cpfTextField.setVisible(true);
            avancarButton.setVisible(true);

        }
    }//GEN-LAST:event_blogRadioButtonActionPerformed

    private void compraRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_compraRadioButtonActionPerformed

        blogRadioButton.setSelected(false);
        relatorioRadioButton.setSelected(false);

        avancarButton.setEnabled(false);

        if(compraRadioButton.isSelected() == false){
            cpfLabel.setVisible(false);
            cpfTextField.setVisible(false);
            avancarButton.setVisible(false);
        }
        else {
            cpfLabel.setVisible(true);
            cpfTextField.setVisible(true);
            avancarButton.setVisible(true);
        }

    }//GEN-LAST:event_compraRadioButtonActionPerformed

    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EscolhaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EscolhaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EscolhaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EscolhaView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
               EscolhaView  Escolha = new EscolhaView();
               Escolha.setLocationRelativeTo(null);
               Escolha.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton avancarButton;
    private javax.swing.JRadioButton blogRadioButton;
    private javax.swing.JRadioButton compraRadioButton;
    private javax.swing.JLabel cpfLabel;
    private java.awt.TextField cpfTextField;
    private javax.swing.JLabel jLabel1;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JRadioButton relatorioRadioButton;
    // End of variables declaration//GEN-END:variables
}
